image thumbnail
from toy compiler by Bill McKeeman
A toy compiler

lexer_test.m
% FILE:    lexer_test.m
% PURPOSE: Smoke test for lexer.m
% METHOD:  try on lexable strings in tiny subset of M
%          show source and tokens
% USAGE:   >> lexer_test

src        = 'a b1	Cc d_1 0 12 12c ()*/\+-=;';
[tc,ts,te] = lexer(src);                % lex source text

disp(src);                              % the source text
for i=1:length(tc)                      % the tokens
  disp([src(ts(i):te(i)) '    token code: ' num2str(tc(i))]);
end

Contact us at files@mathworks.com