16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Development Tools<br />

}<br />

- This is processed by yacc into file called y.tab.c<br />

C statements from between %{ and %}, if any<br />

C statements from after second %%, if any<br />

main() { ...; yyparse(), ...}<br />

yylex(){ ... }<br />

...<br />

yyparse() ( parser, which calls yylex )<br />

- Using lex and yacc<br />

LEX<br />

- Input to lex:<br />

definitions<br />

%%<br />

rules<br />

%%<br />

user subroutines<br />

lexical rules grammar rules<br />

| |<br />

lex<br />

yacc<br />

| |<br />

input yylex yyparse parsed input<br />

lex regular expressions<br />

[a-z]*<br />

any number of characters, including zero<br />

[a-z]+<br />

one or more characters<br />

[A-Z][a-z][A-Za-zO-9]* all strings <strong>with</strong> leading character<br />

| or<br />

ab?c<br />

optional – matches ac or abc<br />

Example:<br />

/*<br />

$ lex scan.1 ==> lex.yy.c<br />

*/<br />

D [0-9]<br />

E [DEde][-+]?{D}+<br />

%%<br />

{D}+ printf("integer");<br />

(D)+"."{D}*({E})? | /* at least one digit before . */<br />

(D)*"."{D}+({E})? | /* at least one digit after . */<br />

{D}+{E}<br />

printf("real");<br />

%%<br />

63

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!