This shows you the differences between two versions of the page.
|
cpl-atm:laboratoare:laborator1 [2013/10/18 10:06] alexandru.radovici created |
cpl-atm:laboratoare:laborator1 [2013/10/18 12:03] (current) laura.vasilescu [Exemplu 1] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Laborator 1 ====== | ====== Laborator 1 ====== | ||
| + | [[http://zaach.github.io/jison/|Jison]] | ||
| + | |||
| + | ===== Exemplu 1 ======= | ||
| + | |||
| + | <code js> | ||
| + | %lex | ||
| + | %% | ||
| + | |||
| + | [0-9]+ return 'NUMBER' | ||
| + | '+' return '+' | ||
| + | '-' return '-' | ||
| + | |||
| + | /lex | ||
| + | %% | ||
| + | |||
| + | expr : NUMBER '+' NUMBER { alert(parseInt($1)+parseInt($3)); } | ||
| + | | NUMBER '-' NUMBER { alert(parseInt($1)-parseInt($3)); } | ||
| + | | NUMBER { $$ = parseInt($1); } | ||
| + | ; | ||
| + | </code> | ||
| + | |||
| + | <hidden> | ||
| + | ===== Exemplu 2 ======= | ||
| + | |||
| + | <code js> | ||
| + | %lex | ||
| + | %% | ||
| + | |||
| + | [0-9]+ return 'NUMBER' | ||
| + | '+' return '+' | ||
| + | '-' return '-' | ||
| + | '*' return '*' | ||
| + | '/' return '/' | ||
| + | |||
| + | /lex | ||
| + | %% | ||
| + | |||
| + | start : e+ { return $1; }; | ||
| + | |||
| + | e : m '+' m { $$ = $1 + $3; } | ||
| + | | m '-' m { $$ = $1 - $3; } | ||
| + | | m { $$ = $1; } | ||
| + | ; | ||
| + | |||
| + | m : f '*' f { $$ = $1 * $3; } | ||
| + | | f '/' f { $$ = $1 / $3; } | ||
| + | | f { $$ = $1; } | ||
| + | ; | ||
| + | |||
| + | f : NUMBER { $$ = parseInt ($1); }; | ||
| + | </code> | ||
| + | </hidden> | ||