Example of (Crude) Lexical Analysis
$ident = "[a-zA-Z][a-zA-Z0-9]*";
$int = "[\-]?[0-9]+";
$op = "[\-\+\*\/\=]|mod";
$exp = "begin x = 5; print sqrt(x); end";
$exp =~ s/$ident/ID/g;
$exp =~ s/$int/N/g;
$exp =~ s/$op/OP/g;
print $exp;
ID ID OP N; ID ID(ID); ID
Previous slide
Next slide
Back to first slide
View graphic version