Skip to content

Instantly share code, notes, and snippets.

@island205
Created May 30, 2012 09:59
Show Gist options
  • Save island205/2835281 to your computer and use it in GitHub Desktop.
Save island205/2835281 to your computer and use it in GitHub Desktop.
模板语言语法分析
{{Variable}}
{{#if conditions}}
BLOCK
{{/if}}
{{#if conditions}}
BLOCK
{{#elseif conditions}}
ELSEIF BLOCK
{{#else}}
ELSE BLOCK
{{/if}}
{{#each conditions as value index}}
BLOCK
{{/each}}
{{#! comments}}
/* description: Parses end executes mathematical expressions. */
/* lexical grammar */
%lex
%%
\s+ /* skip whitespace */
<<EOF>> return 'EOF';
/lex
/* operator associations and precedence */
%start expressions
%% /* language grammar */
expressions
: e EOF
{print($1); return $1;}
;
e
: e '+' e
{$$ = $1+$3;}
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment